<template>
    <div>
        <Table :columns="columns15" :data="data11" border show-summary :summary-method="handleSummary"></Table>

    </div>
</template>

<script>
import { getCountAllList, selectAllT } from '@/api/user'
export default {

  name: 'test',

  data () {
    return {
      columns15: [
        {
          title: '序号',
          key: 'index',
          width: '100',
          align: 'center',
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + 1)
          }
        },
        {
          title: '单位名',
          key: 'company',
          width: '100',
          align: 'center',
          fixed: 'left'
        },
        {
          title: '导入数据总体情况',
          align: 'center',
          width: '300',
          children: [
            {
              title: '加油卡数量',
              key: 'card_num',
              align: 'center',
              width: '100'
            },
            {
              title: '流水条数',
              key: 'number',
              align: 'center',
              width: '100'
            },
            {
              title: '金额（元）',
              key: 'money',
              align: 'center',
              width: '100'
            }
          ]
        },
        {
          title: '存在问题总体情况（去重）',
          align: 'center',
          width: '600',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'question_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.question_isNo === 1 ? '是' : '否')
              }
            },
            {
              title: '占总数比例（%）',
              key: 'company_num_percent',
              align: 'center',
              width: '100'
            },
            {
              title: '涉及加油卡数量',
              key: 'question_card_All',
              align: 'center',
              width: '100'
            },
            {
              title: '占总数比例（%）',
              key: 'card_percent',
              align: 'center',
              width: '100'
            },
            {
              title: '涉及流水条数',
              key: 'question_number_All',
              align: 'center',
              width: '100'
            },
            {
              title: '占总数比例（%）',
              key: 'number_percent',
              align: 'center',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              key: 'question_money_All',
              align: 'center',
              width: '100'
            },
            {
              title: '占总数比例（%）',
              key: 'money_percent',
              align: 'center',
              width: '100'
            }
          ]
        },
        {
          title: '节假日加油情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              width: '100',
              key: 'holiday_isNo',
              render: (h, params) => {
                return h('span', params.row.holiday_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              width: '100',
              key: 'holiday_card_num'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              width: '100',
              key: 'holiday_number'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              width: '100',
              key: 'holiday_money'
            }
          ]
        },
        {
          title: '异地加油情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              width: '100',
              key: 'placeother_isNo',
              render: (h, params) => {
                return h('span', params.row.placeother_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'placeother_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'placeother_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'placeother_money',
              width: '100'
            }
          ]
        },
        {
          title: '用卡购物情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'shopping_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.shopping_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'shopping_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'shopping_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'shopping_money',
              width: '100'
            }
          ]
        },
        {
          title: '超量加油情况（60L)',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'over_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.over_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'over_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'over_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'over_money',
              width: '100'
            }
          ]
        },
        {
          title: '高标号燃油情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'highgrade_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.highgrade_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'highgrade_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'highgrade_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'highgrade_money',
              width: '100'
            }
          ]
        },
        {
          title: '汽柴油混加情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'blend_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.blend_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'blend_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'blend_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'blend_money',
              width: '100'
            }
          ]
        },
        {
          title: '一日多次情况',
          align: 'center',
          width: '400',
          children: [
            {
              title: '是否存在问题',
              align: 'center',
              key: 'manytimes_isNo',
              width: '100',
              render: (h, params) => {
                return h('span', params.row.manytimes_isNo === '1' ? '是' : '否')
              }
            },
            {
              title: '涉及加油卡数量',
              align: 'center',
              key: 'manytimes_card_num',
              width: '100'
            },
            {
              title: '涉及流水条数',
              align: 'center',
              key: 'manytimes_number',
              width: '100'
            },
            {
              title: '涉及金额（元）',
              align: 'center',
              key: 'manytimes_money',
              width: '100'
            }
          ]
        }
      ],
      data11: []
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    getAllNum (allnum) {
      console.log(allnum, 'allnum')
      getCountAllList().then(ret => {
        let tmpArray = []
        ret.data.data.forEach(item => {
          let tempData = {
            card_num: item.card_num,
            company: item.company,
            money: item.money,
            number: item.number
          }
          if (item.subList_count && item.subList_count.length > 0) {
            for (let i = 0; i < item.subList_count.length; i++) {
              for (let key1 in item.subList_count[i]) {
                tempData['question_' + key1] = item.subList_count[i][key1]
              }
            }
          }
          tempData.question_isNo = tempData.question_isNo || 0
          tempData.company_num_percent = (tempData.question_company_num / allnum.company_numAll * 100).toFixed(2)
          tempData.card_percent = (tempData.question_card_All / allnum.card_numAll * 100).toFixed(2)
          tempData.number_percent = (tempData.question_number_All / allnum.numAll * 100).toFixed(2)
          tempData.money_percent = (tempData.question_money_All / allnum.moneyAll * 100).toFixed(2)
          if (item.subMap_duoci && item.subMap_duoci.length > 0) {
            for (let key1 in item.subMap_duoci[0]) {
              tempData['placeother_' + key1] = item.subMap_duoci[0][key1]
            }
          }
          if (item.subMap_fule && item.subMap_fule.length > 0) {
            for (let key1 in item.subMap_fule[0]) {
              tempData['over_' + key1] = item.subMap_fule[0][key1]
            }
          }
          if (item.subMap_mySee && item.subMap_mySee.length > 0) {
            for (let key1 in item.subMap_mySee[0]) {
              tempData['highgrade_' + key1] = item.subMap_mySee[0][key1]
            }
          }
          if (item.subMap_qcList && item.subMap_qcList.length > 0) {
            for (let key1 in item.subMap_qcList[0]) {
              tempData['blend_' + key1] = item.subMap_qcList[0][key1]
            }
          }
          if (item.subMap_shui && item.subMap_shui.length > 0) {
            for (let key1 in item.subMap_shui[0]) {
              tempData['holiday_' + key1] = item.subMap_shui[0][key1]
            }
          }
          if (item.subMap_xiaoe && item.subMap_xiaoe.length > 0) {
            for (let key1 in item.subMap_xiaoe[0]) {
              tempData['shopping_' + key1] = item.subMap_xiaoe[0][key1]
            }
          }
          if (item.subMap_zhouliu && item.subMap_zhouliu.length > 0) {
            for (let key1 in item.subMap_zhouliu[0]) {
              tempData['manytimes_' + key1] = item.subMap_zhouliu[0][key1]
            }
          }
          tmpArray.push(tempData)
        })
        this.data11 = tmpArray
        console.log(this.data11, 'this.data11 ')
      })
    },
    async init () {
      selectAllT().then(ret => {
        console.log(ret.data.errmsg, 'ret@@@@@@@')
        if (ret.data.errcode === 0) {
          let temp = Object.assign(ret.data.data[0], ret.data.data[1])
          this.getAllNum(temp)
        } else {
          this.$Notice.error({
            title: ret.data.errmsg
          })
        }
      })

      // this.data11.forEach(item => {
      //   if (item.amount2 === '') {
      //     item.amount1 = '0'
      //   } else {
      //     item.amount1 = '1'
      //   }
      //   console.log(item, 'item!!!!!!!!')
      // })
    },
    handleSummary ({ columns, data }) {
      const sums = {}
      columns.forEach((column, index) => {
        const key = column.key
        if (index === 0) {
          sums[key] = {
            key,
            value: '总数'
          }
          return
        }
        const values = data.map(item => Number(item[key]))
        if (!values.every(value => isNaN(value))) {
          const v = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[key] = {
            key,
            value: key.indexOf('percent') >= 0 ? v.toFixed(0) : v
          }
        } else {
          sums[key] = {
            key,
            value: this.data11.length
          }
        }
      })

      return sums
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>

</style>
